package cn.xinfei.xdecision.constant;

/**
 * fail：直接结束，不需要再次处理，拒绝接收
 * success：终态或者中间态
 */
public enum EngineResultEnum {


    APPLY("PROCESSING", "SUCCESS", "0x0000", "待处理"),
    PROCESSING("PROCESSING", "SUCCESS", "0x0001", "处理中"),

    SUCCESS_HIT_END("REJECT", "SUCCESS", "0x0002", "正常结束，命中终止条件"),
    SUCCESS_END("PASS", "SUCCESS", "0x0003", "正常结束，到达终止节点"),
    REJECT("REJECT", "SUCCESS", "0x0100", "拒绝，以实际决策配置为准"),

    PENDING("PENDING", "SUCCESS", "0x0004", "挂起中"),
    PENDING_REENTRY("PENDING", "SUCCESS", "0x0005", "挂起中，重入时的入口reentry"),
    CREDIT_PENDING_APPLY("PENDING", "SUCCESS", "0x0006", "挂起中,申请阶段"),
    CREDIT_PENDING_FETCH("PENDING", "SUCCESS", "0x0007", "挂起中,取数阶段"),
    CREDIT_PENDING_END("PENDING", "SUCCESS", "0x0008", "挂起中，征信变量查询终止"),
    CREDIT_PENDING_TIMEOUT("PENDING", "SUCCESS", "0x0009", "人行节点重入超时 "),

    EXCEPTION_END("EXCEPTION", "SUCCESS", "0x0020", "异常结束，决策流执行异常"),
    EXCEPTION_NO_NEXT_END("EXCEPTION", "SUCCESS", "0x0021", "异常结束，没有下一节点"),
    EXCEPTION_NODE_NULL_END("EXCEPTION", "SUCCESS", "0x0022", "异常结束，节点内容为空"),
    EXCEPTION_TIMEOUT("EXCEPTION", "SUCCESS", "0x0023", "异常未结束，决策流超时"),

    DATASOURCE_TIMEOUT("PENDING", "SUCCESS", "0x0024", "异常未结束，数据源超时"),
    DATASOURCE_EXCEPTION("PENDING", "SUCCESS", "0x0025", "异常未结束，数据源异常"),
    DATASOURCE_FAIL("PENDING", "SUCCESS", "0x0026", "异常未结束，数据源失败"),
    DATASOURCE_PENDING("PENDING", "SUCCESS", "0x0027", "数据源重试后，依然失败"),

    NOT_ALLOW_BIZ_NULL("EXCEPTION", "FAIL", "0x0028", "bizId不允许为空"),
    NOT_ALLOW_REQUEST_ID_NULL("EXCEPTION", "FAIL", "0x0029", "requestId不允许为空"),
    NOT_ALLOW_TP_CODE_NULL("EXCEPTION", "FAIL", "0x0030", "tpCode不允许为空"),
    NOT_ALLOW_SCENE_NULL("EXCEPTION", "FAIL", "0x0031", "scene不允许为空"),
    NO_EXISTS("EXCEPTION", "FAIL", "0x0032", "请求引擎不存在或尚未部署运行"),
    NO_DATA("EXCEPTION", "FAIL", "0x0033", "数据不存在"),
    NO_DATA_STACK("EXCEPTION", "FAIL", "0x0034", "stack is empty"),
    FAIL("EXCEPTION", "FAIL", "0x0035", "失败"),
    EXCEPTION("EXCEPTION", "FAIL", "0x0036", "异常"),

    REVIEW("REVIEW", "FAIL", "0x0040", "REVIEW"),

    FAIL_NO_PERMISSION("NO_PERMISSION", "FAIL", "0x0050", "失败"),


    ;
    private String result;
    private String state;
    private String code;
    private String msg;

    /**
     * 对应的业务状态
     */

    EngineResultEnum(String result, String state, String code, String msg) {
        this.code = code;
        this.state = state;
        this.msg = msg;
        this.result = result;
    }

    public String getState() {
        return state;
    }

    public String getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public String getResult() {
        return result;
    }

    public static EngineResultEnum getByCode(String code) {
        EngineResultEnum[] values = EngineResultEnum.values();
        for (int i = 0; i < values.length; i++) {
            if (values[i].code.equals(code)) {
                return values[i];
            }
        }
        return null;
    }
}
